package com.xzx.ecommercedw.common;

import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author xinzhixuan
 * @version 1.0
 * @date 2024/9/17 21:44
 */
@Slf4j
public class DateUtil {

    public static long parse(String str) {
        try {
            return new SimpleDateFormat("yyyy-MM-dd").parse(str).getTime();
        } catch (ParseException e) {
            log.error("parse str error. str:{}", str, e);
            throw new RuntimeException(e);
        }
    }

    public static long getTodayTs() {
        Calendar instance = Calendar.getInstance();
        instance.setTime(new Date());
        instance.set(Calendar.HOUR_OF_DAY, 0);
        instance.set(Calendar.MINUTE, 0);
        instance.set(Calendar.SECOND, 0);
        instance.set(Calendar.MILLISECOND, 0);
        return instance.getTimeInMillis();
    }

    public static void main(String[] args) {
        System.out.println(getTodayTs());
    }
}
